package nc.tb.app.adjustbill.ui;

import java.util.Collection;

import nc.bs.framework.common.NCLocator;
import nc.itf.uap.IUAPQueryBS;
import nc.tb.app.vo.WtAdjustBillBVO;
import nc.ui.trade.adapter.CtrlDelegatorAdapter;
import nc.ui.trade.bsdelegate.BusinessDelegator;
import nc.ui.trade.controller.IControllerBase;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.CircularlyAccessibleValueObject;

public class AdjustBillDelegatorAdapter extends CtrlDelegatorAdapter{

	public AdjustBillDelegatorAdapter(BusinessDelegator delegator,
			IControllerBase uiCtrl) {
		super(delegator, uiCtrl);
	}
	
	public void checkAndGetBodyVO(AggregatedValueObject billVO) throws Exception {
		if (billVO == null)
			return;
		CircularlyAccessibleValueObject headVO = (CircularlyAccessibleValueObject) billVO.getParentVO();
		CircularlyAccessibleValueObject[] vos = billVO.getChildrenVO();
		if (vos == null || vos.length == 0){
			IUAPQueryBS service = NCLocator.getInstance().lookup(IUAPQueryBS.class);
			Collection<WtAdjustBillBVO> c = service.retrieveByClause(WtAdjustBillBVO.class, "pk_adjustbill = '" + headVO.getPrimaryKey() + "' and dr = 0");
			billVO.setChildrenVO(c.toArray(new WtAdjustBillBVO[0]));
		}
	}

}
